package com.dragon.concurrent.demo.readandwrite;

public class Gate {

    private String name = "noBody";

    private String address = "noWhere";

    private int counter = 0;

    public Gate(String name, String address, int counter) {
        this.name = name;
        this.address = address;
        this.counter = counter;
    }

    public Gate() {

    }

    public synchronized void pass(String name, String address) {
        this.name = name;
        this.address = address;
        this.counter++;
        verify();
    }

    public void verify() {
        if (this.name.charAt(0) != this.address.charAt(0)) {
            System.out.println("*********BROKEN******************" + toString());
            return;
        }
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "name:" + this.name +" address:" + this.address + " counter:" + this.counter;
    }
}
